﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 提交管理平台V1
{
    public partial class frmDPAIDViewer : Form
    {
        string strDefaultSelectString = "select * from DPA报告编号表";

        public frmDPAIDViewer()
        {
            InitializeComponent();
        }

        private void chkDateRange_CheckedChanged(object sender, EventArgs e)
        {
            dtpFrom.Enabled = chkDateRange.Checked ;
            dtpTo.Enabled = chkDateRange .Checked ;
        }

        private void chkSN_CheckedChanged(object sender, EventArgs e)
        {
            txtSN.Enabled = chkSN .Checked ;
        }

        private void chkModel_CheckedChanged(object sender, EventArgs e)
        {
            txtModel.Enabled = chkModel.Checked;
        }

        private void chkDPAID_CheckedChanged(object sender, EventArgs e)
        {
            txtDPAID.Enabled = chkDPAID.Checked;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string strSelectString = strDefaultSelectString;
            if (chkDateRange.Checked)
            {
                if (strSelectString.Contains(" where "))
                {
                    strSelectString += " and ";
                }
                else
                {
                    strSelectString += " where ";
                }
                strSelectString += "打印时间 between '" + dtpFrom.Value.ToString("yyyy-MM-dd") + "' and '" + dtpTo.Value.ToString("yyyy-MM-dd") + "'";
            }
            if (chkSN.Checked)
            {
                if (strSelectString.Contains(" where "))
                {
                    strSelectString += " and ";
                }
                else
                {
                    strSelectString += " where ";
                }
                strSelectString += "批号 like '" + txtSN.Text + "'";
            }
            if (chkModel.Checked)
            {
                if (strSelectString.Contains(" where "))
                {
                    strSelectString += " and ";
                }
                else
                {
                    strSelectString += " where ";
                }
                strSelectString += "型号规格 like '" + txtModel.Text + "'";
            }
            if (chkDPAID.Checked)
            {
                if (strSelectString.Contains(" where "))
                {
                    strSelectString += " and ";
                }
                else
                {
                    strSelectString += " where ";
                }
                strSelectString += "DPA报告编号 like '" + txtDPAID.Text + "'";
            }
            SqlTools sqt = new SqlTools(GeneralTools.GetConnectionString(提交管理平台V1.Properties.Settings.Default.Host, "DefualtDataBase"));
            DataTable tmpdt = sqt.GetData(strSelectString);
            dgv1.DataSource = tmpdt;
            dgv1.AutoResizeColumns();
        }
    }
}